package org.yxj.videolibrary.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;

/**
 * 状态栏相关
 *
 * @author on 2022/9/12
 */
public class SubmergedBarUtil {


    /**
     * 沉嵌式 状态栏
     *
     * @param context
     */
    public static void submergedBar(Activity context){
        if (Build.VERSION.SDK_INT >=19 && Build.VERSION.SDK_INT < 21) {
            //透明状态栏
            context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }else if (Build.VERSION.SDK_INT >= 21) {
            View decorView =context. getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE ;
            decorView.setSystemUiVisibility(option);
            context.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
    }

    /**
     * 获得状态栏的高度
     * @param context
     * @return
     */
    public static int getStatusBarHeight(Context context) {
        int result = 0;
        if (Build.VERSION.SDK_INT>=19) {
            int resourceId = context.getResources().getIdentifier("status_bar_height",
                    "dimen", "android");
            if (resourceId > 0) {
                result = context.getResources().getDimensionPixelSize(resourceId);
            }
            return result;
        }
        return result;
    }



    /**
     * 设置状态栏的颜色
     * @param b
     */
    public static void setTitleBarColor(Activity activity, boolean b){
        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
            View decorView =activity.getWindow().getDecorView();
            int option ;
            if (b){
                /*白色*/
                option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE ;
            }else {
                //黑色
                option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR ;
            }
            decorView.setSystemUiVisibility(option);
            activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
    }
}
